<?php

include 'autoload.php';

$id_usuarios = $sessao->getValor('sessao_id_usuarios');
$id_menu = (isset($_GET['id_menu'])) ? intval($_GET['id_menu']) : null;
try{
$select = new SelectBox();
$select->setClass('selectmenu input-sm col-lg-10 SelectedNull');
$select->setId('id_menu_pai');
$select->setNome('id_menu_pai');
$select->setValida('nao,,Menu');
$select->setSql("SELECT `menu`.`id_menu` , `menu`.`menu` AS nomeMenu
                FROM `menu`
                WHERE `ativo` =1
                AND `id_menu_pai` IS NULL ");
$select->setValorOption('id_menu');
$select->setTextoOption('nomeMenu');
if (!empty($id_menu)) {
    $sql = "SELECT * FROM menu WHERE id_menu = :id_menu";
    $params = array(
        'id_menu' => array(
            'valor' => $id_menu,
            'pdotype' => PDO::PARAM_INT
        )
    );

    $crud = new SqlCrud();
    $dados = $crud->executaSql($sql, $params);
    $select->setCampoSelecionado($dados[0]['id_menu_pai']);
} else {
    $dados[0] = array(
        'id_menu' => null,
        'id_usuarios' =>  $id_usuarios,
        'menu' => '',
        'menu_en' => '',
        'menu_es' => '',
        'aparecer_menu' => 1,
        'ordenar' => ''
    );
}
} catch (PDOException $e){
    new Excecao($e);
}
$smarty->assign('select', $select->CriaSelect());
$smarty->assign('dados', $dados[0]);
$smarty->assign('id_usuarios', $id_usuarios);
$smarty->assign('id_menu', $id_menu);
$smarty->display('cadastra_menu.tpl');